import { useEffect } from 'react';
import {
  ProFormText,
  ProFormSelect,
  ProForm,
  ProFormDigit,
  ProFormDependency,
} from '@ant-design/pro-components';
import type { ProFormInstance } from '@ant-design/pro-components';
import StorageManager from '@/utils/StorageManager';
import {
  ENUM_INVOICE_TYPE,
  ENUM_FINACNCE_SHARE_OBJECT,
  ENUM_FINACNCE_SHARE_TYPE,
  ENUM_UNITPRICE_SOURCE,
} from '../constants';
import Config from '../configGroup';
import styles from './style.less';

type Props = {
  isModify?: boolean;
  isRead?: boolean;
  formRef: ProFormInstance | any;
};

const FinanceInfo: React.FC<Props> = ({ isModify, isRead, formRef }) => {
  const eunmList: any = StorageManager.getLocalStorageSync('eunmList');
  const OptionsFinanceBrandList = eunmList?.OptionsFinanceBrandList || [];
  const OptionsRevenueTypeList = eunmList?.OptionsRevenueTypeList || [];

  // 枚举值查询
  useEffect(() => {
    // dispatch('queryOptionsFinanceBrandList');
    // dispatch('queryOptionsRevenueTypeList');
  }, []);

  return (
    <Config.Group id="finance-info" title="财务信息">
      <div className={styles['wrap-body']}>
        <ProForm.Group>
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="invoiceType"
            label="开票节点"
            options={ENUM_INVOICE_TYPE}
            placeholder="InvoiceType"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="payerName"
            label="结算方"
            placeholder="PayerName"
            // // rules={[{ required: true, message: '不得为空' }]}
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="applyName"
            label="申请方法人公司"
            placeholder="ApplyName"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="applyJDE"
            label="申请方法人公司JDE"
            placeholder="ApplyJDE"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="faceAmount"
            label="券面值"
            placeholder="FaceAmount"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="internalCouponPrice"
            label="内部结算价格"
            placeholder="InternalCouponPrice"
          />
          <div style={{ position: 'relative' }}>
            <ProFormText
              labelCol={{ span: 8 }}
              width={150}
              name="sales"
              label="销售价格(净收入)/券净值"
              placeholder="Sales"
            />
            <div style={{ position: 'absolute', top: 0, right: 1 }}>(注)-1参考餐牌价</div>
          </div>
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="discountinSales"
            label="第三方支付的折扣"
            placeholder="DiscountinSales"
          />

          <ProFormDependency name={['tenderTypeDesc']}>
            {({ tenderTypeDesc }) => {
              if (['会员费'].includes(tenderTypeDesc)) {
                return (
                  <div style={{ marginRight: 110 }}>
                    <ProFormDigit
                      labelCol={{ span: 10 }}
                      width="md"
                      name="invoiceAmountA"
                      label="给顾客开票的金额"
                      fieldProps={{ precision: 0, addonAfter: '%' }}
                      placeholder="invoiceAmountA"
                    />
                  </div>
                );
              }
              return (
                <ProFormText
                  labelCol={{ span: 8 }}
                  width="lg"
                  name="invoiceAmountA"
                  label="给顾客开票的金额"
                  placeholder="invoiceAmountA"
                />
              );
            }}
          </ProFormDependency>

          <ProFormDependency name={['tenderTypeDesc']}>
            {({ tenderTypeDesc }) => {
              if (['会员费'].includes(tenderTypeDesc)) {
                return (
                  <ProFormDigit
                    labelCol={{ span: 8 }}
                    width="lg"
                    name="invoiceAmountB"
                    label="给第三方开票的金额"
                    fieldProps={{ precision: 0, addonAfter: '%' }}
                    placeholder="invoiceAmountB"
                  />
                );
              }
              return (
                <ProFormText
                  labelCol={{ span: 8 }}
                  width="lg"
                  name="invoiceAmountB"
                  label="给第三方开票的金额"
                  placeholder="invoiceAmountB"
                />
              );
            }}
          </ProFormDependency>
          {/* 占位 */}
          <div style={{ width: 1500 }} />

          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="salesRedeemCount"
            label="结算次数"
            placeholder="salesRedeemCount"
            // rules={[{ required: true, message: '不得为空' }]}
          />
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="finacnceShareObject"
            label="分摊对象"
            options={ENUM_FINACNCE_SHARE_OBJECT}
            placeholder="finacnceShareObject"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="financeFV"
            label="权益面额信息"
            placeholder="financeFV"
            // rules={[{ required: true, message: '不得为空' }]}
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="financeUsedCount"
            label="预计使用量"
            placeholder="financeUsedCount"
            // rules={[{ required: true, message: '不得为空' }]}
          />
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="financeShareType"
            label="分摊方式"
            options={ENUM_FINACNCE_SHARE_TYPE}
            placeholder="financeShareType"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="financePrice"
            label="商品售价标准价"
            placeholder="financePrice"
            // rules={[{ required: true, message: '不得为空' }]}
          />
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="finaceSalesBrand"
            label="余额归属品牌"
            options={OptionsFinanceBrandList}
            placeholder="finaceSalesBrand"
          />
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="financeRevenueType"
            label="收入类型"
            options={OptionsRevenueTypeList}
            placeholder="financeRevenueType"
          />
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="tocstoreid"
            label="2C售卖餐厅"
            placeholder="tocstoreid"
          />
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="unitpricesource"
            label="单价来源"
            options={ENUM_UNITPRICE_SOURCE}
            placeholder="unitpricesource"
          />
        </ProForm.Group>
      </div>
    </Config.Group>
  );
};

export default FinanceInfo;
